package javasec.contempt.dialogs;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class StringDialog extends Dialog
{
	String windowName="";
	
	String[] stringValues=null;
	String[] promptArray;
	Text[] stringText;
	public boolean aborted=true;
	
	public StringDialog(Shell parent,String wName,String[] pArray)
	{
		super(parent);
		
		promptArray=pArray;
		windowName=wName;
	}
	
	public String[] getValues()
	{
		return stringValues;
	}
	
	protected void okPressed()
	{
		aborted=false;
		stringValues=new String[promptArray.length];
		
		for(int x=0;x<promptArray.length;++x)
		{
			stringValues[x]=stringText[x].getText();
		}
		
		super.okPressed();
	}
	
	protected Control createDialogArea(Composite parent)
	{
		
		Composite composite = new Composite(parent,0);
		composite.setLayout(new GridLayout(2,false));
		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
	
		stringText=new Text[promptArray.length];
		for(int x=0;x<promptArray.length;++x)
		{
			Label stringLabel=new Label(composite,SWT.None);
			stringLabel.setText(promptArray[x]);
			stringLabel.pack();
		
			stringText[x]=new Text(composite,SWT.LEFT|SWT.BORDER);
			stringText[x].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		}
			
		return composite;
	}
	
	protected void configureShell(Shell newShell)
	{
		super.configureShell(newShell);
		newShell.setText(windowName);
	}
}
